
import java.util.Arrays;

public class Zcsh {
    public static int maximalRectangle(char[][] matrix) {

        if (matrix == null || matrix.length == 0) return 0;
        int maxArea = 0;

        int[] left = new int[matrix[0].length];
        int[] right = new int[matrix[0].length];
        int[] height = new int[matrix[0].length];

        Arrays.fill(right, matrix[0].length);

        for (int i = 0; i < matrix.length; i++) {
            int cur_left = 0, cur_right = matrix[0].length;
            for (int j = 0; j < matrix[0].length; j++) {
                if (matrix[i][j] == '1') {
                    height[j]++;
                    left[j] = Math.max(left[j], cur_left);
                    right[j] = Math.min(right[j], cur_right);
                } else {
                    height[j] = 0;
                    left[j] = 0;
                    cur_left = j + 1;
                    right[j] = matrix[0].length;
                    cur_right = j;
                }
            }

            for (int j = 0; j < matrix[0].length; j++) {
                maxArea = Math.max(maxArea, (right[j] - left[j]) * height[j]);
            }
        }
        return maxArea;
    }
}